package com.briup.mt.service.impl;

import com.briup.mt.bean.DatasetFile;
import com.briup.mt.bean.DatasetFileExample;
import com.briup.mt.dao.DatasetFileMapper;
import com.briup.mt.service.IDatasetFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service
public class DatasetFileServiceImpl implements IDatasetFileService {

    @Autowired
    private DatasetFileMapper datasetFileMapper;

    @Override
    public List<DatasetFile> query(String name,Long datasetId){
        DatasetFileExample example=new DatasetFileExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andFileRealNameLike("%"+ name +"%");
        }
        if (datasetId !=null){
            example.createCriteria().andDatasetIdEqualTo(datasetId);
        }
        return datasetFileMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(DatasetFile datasetFile){
        if (datasetFile.getId()==null){
            datasetFileMapper.insert(datasetFile);
        }else{
            datasetFileMapper.updateByPrimaryKey(datasetFile);
        }
    }
    @Override
    public void deleteById(long id){
        datasetFileMapper.deleteByPrimaryKey(id);
    }
}
